package com.stox.client.ui.javafx.chartingy.widget.menu;

import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.control.MenuItem;

import com.stox.client.core.model.intf.HasNavigable;
import com.stox.client.core.model.intf.Navigable;
import com.stox.client.ui.javafx.chartingy.view.ChartingViewDisplayHelper;
import com.stox.shared.i18n.MessageSource;
import com.stox.shared.model.intf.HasScrip;

public class MultiChartMenuItem extends MenuItem implements
		ChartingMenuItemMarker, EventHandler<ActionEvent> {

	private final ChartingViewDisplayHelper chartingViewDisplayHelper;
	
	public MultiChartMenuItem(ChartingViewDisplayHelper chartingViewDisplayHelper) {
		super(MessageSource.get("Display.Independent.Charts"));
		this.chartingViewDisplayHelper = chartingViewDisplayHelper;
		setOnAction(this);
	}

	@SuppressWarnings("unchecked")
	@Override
	public void handle(ActionEvent event) {
		if (getParentPopup() instanceof HasNavigable) {
			HasNavigable<?> hasNavigable = (HasNavigable<?>) getParentPopup();

			if (null != hasNavigable.getNavigable()
					&& HasScrip.class.isAssignableFrom(hasNavigable
							.getNavigable().getNavigableEntityClass())) {
				Navigable<HasScrip> hasScripNavigable = (Navigable<HasScrip>)hasNavigable.getNavigable();
				chartingViewDisplayHelper.multiple(hasScripNavigable);
			}
		}
	}

}
